<template>
  <div>
    <el-table
      :data="orderlist"
      border
      style="width: 100%">
      <el-table-column
        fixed
        prop="time"
        label="日期"
        width="400">
      </el-table-column>
      <el-table-column
        prop="totalprice"
        label="价格"
        width="120">
      </el-table-column>
      <el-table-column
        prop="addrs"
        label="地址"
        width="500">
      </el-table-column>
      <el-table-column
        prop="status"
        label="状态"
        width="500">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="200">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="success" size="small" >查看订单</el-button>
          <el-button type="danger" size="small" @click="handle(scope.row.id)">删除订单</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import jwtDecode from 'jwt-decode'
  export default {
    name: "ordersw",
    data () {
      return {
        orderlist: [],
        decode:{
          user:{}
        },

        user: {
        },
      }
    },
    methods: {
      findAll(){
        var token = window.localStorage.getItem("userS");
        const decode = jwtDecode(token)
        this.user=JSON.parse(decode.user);
        this.$axios.get("/order/findAllByUid?user_id=" +  this.user.id  ).then(res=>{
          this.orderlist = res.data.data;
        })
      },
      handleClick(row) {
        console.log(row);
        this.$router.push({name:"order",params:{id:row.id,totalPrice:row.totalprice}});
      },
      handle(id){

        this.$axios.get("/order/deleteOrderById?id=" +id  ).then(res=>{

          this.findAll();
        })
      }
    },
    mounted(){
      this.findAll();
    }
  }
</script>

<style scoped>

</style>
